import request from '@/utils/request';
import type { ResponseBaseData, QueryParamModel } from '@/api/model/baseModel';
/**
 * 获取流程事件
 * @param params 分页数据
 * @returns 流程事件列表
 */
export function getEventInfolist(params: QueryParamModel): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/design/getEventsByDesignerByPage/v1`, params);
}

/** 流程参与者选择组件BPMSelectUser组件API */
export interface DeptUserTreeModel {
  id?: string;
  type?: string;
  keyword?: string;
}

/**
 * 获取部门维度人员树
 * @param params 部门节点参数
 * @returns 部门维度人员数据(树)
 */
export function getOrgDeptUserTrees({ id, type }: DeptUserTreeModel): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/design/getOrgDeptUserTrees/v1?id=${id}&type=${type}`);
}

/**
 * 根据关键字查询部门维度人员树
 * @param { keyword } 关键字查询参数
 * @returns 部门维度人员数据(树)
 */
export function getOrgDeptUserTreesByKeyWord({ keyword }: DeptUserTreeModel): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/design/getOrgDeptUserTreesByKeyWord/v1?keyword=${keyword}`);
}

/**
 * 获取岗位树
 * @returns 岗位树
 */
export function getOrgPositionTree(): Promise<ResponseBaseData<any>> {
  return request.get('/bpm/design/getOrgPositionTree/v1');
}

/**
 * 获取角色树
 * @returns 角色树
 */
export function getOrgRoleTree(): Promise<ResponseBaseData<any>> {
  return request.get('/bpm/design/getOrgRoleTree/v1');
}

/**
 * 获取群组树
 * @returns 群组树
 */
export function getOrgGroupTree(): Promise<ResponseBaseData<any>> {
  return request.get('/bpm/design/getOrgGroupTree/v1');
}
export function getFlowVersionsByKey(id: string): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/bpmpi/bpmpiprocesss/getVersionsByKey/v1`, { data: { id } });
}

/**
 *  查询表字段
 * @param params 参数
 * @returns 流程事件列表
 */
export function getProcessFormFields(data) {
  return request({
    url: '/bpm/design/getProcessFormFields/v1',
    data,
    method: 'get'
  });
}
/**
 *  查询表字段
 * @param params 参数
 * @returns 流程事件列表
 */
export function getSubProcess(params: any): Promise<ResponseBaseData<any>> {
  return request.post(`bpm/AppBpmSubmitRest/getSubProcess/v1`, params);
}
/**
 * 流程设计器-人工节点-待办标题弹窗ConfigTitle组件所需接口
 * 获取电子表单里勾的流程变量：既包括全局变量里配置的流程变量 又包括电子表单里勾的流程变量
 * */
export function getVariable(data) {
  return request({
    url: '/bpm/design/getProcessFormFieldsForVar/v1',
    data,
    method: 'get'
  });
}
/**
 * 流程设计器-选人组件-候选人配置，自定义函数的事件列表里不显示已添加的数据
 * */
export function getEvents(data) {
  return request({
    url: '/bpm/design/getEventsByDesignerByPage/v1',
    data,
    method: 'post'
  });
}

/**
 * 根据id获取流程事件信息及其关联常量
 * @param dbId
 * @returns
 */
export function getEventInfoForDesigner(dbId) {
  return request.get(`/bpm/design/getEventInfoForDesigner/${dbId}/v1`);
}

/**
 * 获取电子表单的流程变量
 * @param param 电子表单信息 { id }
 * @returns 电子表单流程变量列表
 */
export function getProcessFormFieldsForVar(param: any): Promise<ResponseBaseData<any>> {
  return request({
    url: `/bpm/design/getProcessFormFieldsForVar/v1`,
    data: param,
    method: 'get'
  });
}

/**
 * 获取选择表单树数据
 * @param params {}
 * @returns 选择表单树数据
 */
export function getManagerFormBpmTree(params: any): Promise<ResponseBaseData<any>> {
  return request.post(`/eformvue/dynamicform/DynamicTreeRest/getManagerFormBpmTree/v1`, params);
}

/**
 * 搜索选择表单树数据
 * @param params 搜索关键字 { keyword }
 * @returns 选择表单树数据
 */
export function seachManagerFormBpmTree(params: any): Promise<ResponseBaseData<any>> {
  return request.post(`/eformvue/dynamicform/DynamicTreeRest/seachManagerFormBpmTree/v1`, params);
}
/**
 * 获取电子表单的流程变量
 * @param id 电子表单信息 { id }
 * @returns 电子表单流程变量列表
 */
export function getProcessFormFieldsForVarJoin(id: any): Promise<ResponseBaseData<any>> {
  return request({
    url: `/bpm/design/getProcessFormFieldsForVar/v1?id=${id}`,
    method: 'get'
  });
}
/**
 * 获取流程事件
 * @param params 分页数据
 * @returns 流程事件
 */
export function getEventInfo(params: QueryParamModel): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/design/getEventsByDesigner/v1`, params);
}
/**
 * 获取服务树
 */
export function getTreeData(): Promise<ResponseBaseData<any>> {
  return request.get(`/appsys/ConnectCenter/AppConnectCenterRest/getConnectTypeTree/-1/v1`);
}
